﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class LobbyData {
    private static string fileName = "Client/Config/lobbyTextConfig";
    Hashtable _data;
    private static LobbyData instance;
    public static LobbyData Instance
    {
        get
        {
            if (instance == null)
            {
                instance = loadFromLocal();
            }
            return instance;
        }
    }

    public static LobbyData loadFromLocal()
    {
        LobbyData data = new LobbyData();
        return data;
    }
    private LobbyData()
    {
        TextAsset asset = (TextAsset)Resources.Load(fileName, typeof(TextAsset));
        if(asset == null)
        {
            Debug.Log("Config file:" + fileName + "is not exist or is not text file");
            return ;
        }
        _data = asset.text.hashtableFromJson();
    }
    //根据key值不同得到所有text
    public List<string> getText(string key)
    {
        Hashtable has = (Hashtable)_data[key];
        List<string> lst = new List<string>();
        if (_data.ContainsKey(key))
        {
            for (int i = 0; i < has.Count; i++)
            {
                lst.Add(((Hashtable)has[i.ToString()]).OptString("text"));
            }
            return lst;
        }
        else
        {
            return null;
        }

    }
}
